package org.madgecko.basic.dao.impl;

import org.madgecko.basic.dao.BaseDao;
import org.madgecko.basic.model.Pager;
import org.madgecko.basic.dao.iface.IStudentDao;
import org.madgecko.basic.model.Student;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class StudentDao extends BaseDao<Student> implements IStudentDao {
	@Override
	public Student loadByStuNum(String stuNum) {
		String hql = "from Member s where s.stuNum=?";
		return (Student)this.queryObject(hql, stuNum);
	}

	@Override
	public Pager<Student> findStudentByCon(Integer status, Integer clazzId, String con) {
		String hql = " from Member s where 1=1";
		if(status!=null){
			hql += " and s.status=" + status;
		}
		if(clazzId!=null){
			hql += " and s.clazz.id=" + clazzId;
		}
		if(con!=null&&!"".equals(con.trim())){
			hql += " and s.name like '%" + con + "%' or s.stuNum lile '%" + con + "%'";
		}
		return this.find(hql);
	}

	@Override
	public List<Student> listStudentByClazz(Integer clazzId) {
		String hql = " from Member s where s.clazz.id=" + clazzId;
		return this.list(hql);
	}
}
